package cn.aiweiyi.qingjing.coupon.distribution.converter;


import cn.aiweiyi.qingjing.coupon.comm.constant.CouponStatus;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author 青衿
 * @Date 2020/11/19 8:56
 * 优惠券实体类的状态枚举转换器
 **/
@Converter
public class CouponStatusConverter implements AttributeConverter<CouponStatus, Integer> {
    //增删改时被JPA调用

    @Override
    public Integer convertToDatabaseColumn(CouponStatus status) {
        return status.getCode();
    }

    @Override
    public CouponStatus convertToEntityAttribute(Integer code) {
        return CouponStatus.of(code);
    }
}
